﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Runtime.Remoting;
using Contracts;
using System.Threading;

namespace Radar {
    public class RadarApp {
        private static readonly string configFile = ConfigurationManager.AppSettings["serverConfigFile"];

        public static void Main(String[] args) {
            RemotingConfiguration.Configure(configFile, false);
            Sensor s = new Sensor(60);
            Console.WriteLine("Sensor started...");
            Timer t = new Timer(ShowRep, Repository.GetInstance(), 5000, 5000);
            Console.WriteLine("Timer started...");
            Radar r = new Radar();
            Console.WriteLine("Radar started ...");
            Console.WriteLine("Press Enter to stop server.");
            Console.ReadLine();
        }

        private static void ShowRep(Object o) {
            Console.WriteLine("--------------------------");
            Console.WriteLine("Current registered events:");
            ((IRepository)o).PeekEvents().ForEach(a => Console.WriteLine(a));
            Console.WriteLine("--------------------------");
        }
    }
}
